package com.yc.yyds.biz;

import com.yc.yyds.dao.IndentDao;
import com.yc.yyds.dao.UserLoginDao;

import java.util.Date;
import java.util.List;
import java.util.Map;

public class IndentBiz {
    IndentDao dao  = new IndentDao();
    UserLoginDao userDao = new UserLoginDao();
    public List<Map<String, Object>> query(String userid) throws BizException {
        if (userid.equals("")){
            throw new BizException("业务异常,请联系管理员");
        }
        try {
            return dao.query(userid);
        }catch (Exception e){
            throw new BizException("订单加载失败");
        }
    }
    //取消订单
    public Map<String, Object> cancel(String indentid, String userid,Long time,String ppjhid) throws BizException {
        long cha = time-new Date().getTime();
        if (cha<0){
            throw new BizException("不在退款时间段内,无法退款");
        }
        if (cha<(1000*60*60)){
            throw new BizException("电影放映前1小时内不能取消订单");
        }
        if (indentid.equals("") || userid.equals("")){
            throw new BizException("业务异常,请联系管理员");
        }
        try {
            dao.cancel(indentid,userid,ppjhid);
            return userDao.Map(userid);
        }catch (Exception e){
            throw  new BizException("退款失败,请联系管理员");
        }

    }

}
